<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
        <div class="item">北京</div>
        <div class="item">上海</div>
        <div class="item">广州</div>
</body>
<script>
    var item = document.querySelectorAll(".item")
    for(item of items){
        item.onclick = function() {
            for(n of items){
                n.style.background="#fff"
            }
            this.style.background="#ffooff"
        }
    }
</script>
<style>
    
</style>

</html>